package com.itheima.wisdomnext.entity.Result;

import com.itheima.wisdomnext.entity.Result.enumcalss.ErrorCode;

public class ResponseResult<T> {
    private int code; // 状态码
    private String msg; // 消息
    private T data; // 数据

    // 无参构造
    public ResponseResult() {
    }

    // 全参构造
    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 静态方法构造成功响应
    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(ErrorCode.SUCCESS.getCode(), msg, data);
    }

    // 静态方法构造失败响应
    public static <T> ResponseResult<T> failure(String msg) {
        return new ResponseResult<>(ErrorCode.FAILED.getCode(), msg, null);
    }

    // Getter 和 Setter
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
